import { create } from 'zustand'
// import { immer } from 'zustand/middleware/immer'
interface LoginUserState {
  // 状态
  user: API.LoginUserVO

  // 操作方法
  setUser: (newLoginUser: API.LoginUserVO) => void
}
const initialState: API.LoginUserVO = {
  userName: '未登录',
}
export const useUserStore = create<LoginUserState>()((set) => {
  return {
    user: { ...initialState },
    setUser: (newLoginUser: API.LoginUserVO) => {
      set(() => ({ user: newLoginUser }))
    },
  }
})

export const selectUserName = () => {
  return useUserStore((state) => state?.user?.userName)
}

export const selectUserId = () => {
  return useUserStore((state) => state?.user?.id)
}
